//
//  ZLAlertMainView.m
//  ZLAlert-OC
//
//  Created by 科大 on 2024/1/2.
//

#import "ZLAlertMainView.h"

@implementation ZLAlertMainView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if (self.textField) {
        BOOL inside = CGRectContainsPoint(self.textField.frame, point);
        if (inside) {
            return self.textField;
        }
        
        UITextField *tapView = [self getPointTextField:point];
        if (tapView) {
            return tapView;
        }
        
        [self.textField endEditing:YES];
        return nil;
    }
    
    return [super hitTest:point withEvent:event];
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    if (self.textField) {
        return NO;
    }
    
    return [super pointInside:point withEvent:event];
}

- (UITextField *)getPointTextField:(CGPoint)point {
    for (UIView *view in self.subviews) {
        if (![view isKindOfClass:[UITextField class]]) {
            continue;
        }
        
        UITextField *textField = (UITextField *)view;
        BOOL inside = CGRectContainsPoint(textField.frame, point);
        if (!inside) {
            continue;
        }
        
        return textField;
    }
    
    return nil;
}

@end
